package com.ra.service.impl;

import com.ra.pojo.RespBean;
import com.ra.pojo.UserInfo;
import com.ra.mapper.UserInfoMapper;
import com.ra.pojo.dto.UserDetailsDTO;
import com.ra.pojo.dto.UserInfoDTO;
import com.ra.service.IUserInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 今晚几点睡_Ada
 * @since 2023-03-09
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements IUserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;


    @Override
    public RespBean<?> updateUserInfo(UserInfoDTO userInfoDTO) {
        UserDetailsDTO userDetailsDTO = (UserDetailsDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        UserInfo userInfo = UserInfo.builder()
                .id(userDetailsDTO.getUserInfoId())
                .nickname(userInfoDTO.getNickname())
                .intro(userInfoDTO.getIntro())
                .website(userInfoDTO.getWebsite())
                .build();
        System.out.println("userInfo = " + userInfo);
        userInfoMapper.updateById(userInfo);
        return RespBean.success();
    }
}
